{% extends "layout.html" %}
{% block __data_browser__custom_external_block %}
  <link rel="stylesheet" href="{{ url_for('static', filename="css/customer.css") }}" media="print">
  <script type="text/javascript" src="{{ url_for("static", filename="js/print-area.js") }}"></script>
  <script type="text/javascript">
    $(function () {
      $("#print").click(function () {
            {% if consignment.pay_in_cash == True and consignment.is_paid == false %}
              alert("未付款");
              return false;
            {% else %}
              {% if not consignment.MSSQL_ID %}
                $(this).attr("disabled", true);
                $.post("/delivery/ajax/consignment", {id:{{ consignment.id}}}).error(function (data) {
                  $("button").attr("disabled", false);
                  if (confirm(data.responseText + "，继续打印？")) {
                    printArea(document.querySelector('#printArea'));
                  }
                }).success(function () {
                  printArea(document.querySelector('#printArea'));
                });
              {% else %}
                printArea(document.querySelector('#printArea'));
              {% endif %}

            {% endif %}
          }
      );
    })
  </script>
  <style type="text/css">
    #printArea {
      display: none;
    }
  </style>
{% endblock %}

{% block body %}
  <div class="row">
    <div class="col-lg-6 col-lg-offset-3">
      <h5 class="pull-right">NO. {{ consignment.id }}</h5>

      <table class="table table-striped table-bordered table-condensed">
        <tr>
          <th colspan="5"><h4 class="text-center">金禾域加工发货单</h4></th>
        </tr>
        <tr>
          <th>发货单号</th>
          <td colspan="4"><p
              class="center">{{ consignment.consignment_id }}</p>
          </td>
        </tr>
        <tr>
          <th>公司名称</th>
          <td colspan="4"><p
              class="center">{{ consignment.customer.name }}</p>
          </td>
        </tr>
        <tr>
          <th>车辆车牌号</th>
          <td colspan="4"><p
              class="center">{{ consignment.plate }}</p></td>
        </tr>
        <tr>
          <th>日期</th>
          <td colspan="4"><p
              class="center">{{ consignment.create_time.date() }}</p>
          </td>
        </tr>
        <tr>
          <th>产品名称</th>
          {% if consignment.measured_by_weight %}
            <th colspan="3">净重(公斤)</th>
          {% else %}
            <th>规格 - 型号</th>
            <th>数量</th>
            <th>净重(公斤)</th>
          {% endif %}
          <th>生产班组</th>
        </tr>
        {% for product in consignment.product_list %}
          <tr>
            <td>{{ product.product.name }}</td>
            {% if  consignment.measured_by_weight %}
              <td colspan="3">
                {{ product.weight }}
                {% if product.returned_weight %}
                  (退镀{{ product.returned_weight }}KG)
                {% endif %}
              </td>
            {% else %}
              <td>{{ product.spec + " - " + product.type }}</td>
              <td>{{ product.quantity }}({{ product.unit }})</td>
              <td>
                {{ product.weight }}
                {% if product.returned_weight %}
                  (退镀{{ product.returned_weight }}KG)
                {% endif %}
              </td>
            {% endif %}
            <td>
              {{ product.team.name if product.team else "" }}
            </td>
          </tr>
        {% endfor %}
        <tr>
          <th>备注：</th>
          <td colspan="4">{{ consignment.notes or "" }}</td>
        </tr>
        <tr>
          <td colspan="3">客户签名：</td>
          <td colspan="2">
            总重量(公斤):{{ consignment.product_list|sum(attribute='weight') }}</td>
        </tr>
      </table>
      <p class="text-right">注:若有质量疑义，请在收货之日起三日内以书面形式告知</p>

      <div id="printArea">
        {% for i in range(pages) %}
          <div {% if not loop.last %}class="page-next"{% endif %}>
            <h5 class="pull-right">NO. {{ consignment.id }}</h5>
            <table class="table table-striped table-bordered table-condensed">
              <tr>
                <th colspan="5"><h4 class="text-center">金禾域加工发货单</h4></th>
              </tr>
              <tr>
                <th>发货单号</th>
                <td colspan="4"><p
                    class="center">{{ consignment.consignment_id }}</p>
                </td>
              </tr>
              <tr>
                <th>公司名称</th>
                <td colspan="4"><p
                    class="center">{{ consignment.customer.name }}</p>
                </td>
              </tr>
              <tr>
                <th>车辆车牌号</th>
                <td colspan="4"><p
                    class="center">{{ consignment.plate }}</p></td>
              </tr>
              <tr>
                <th>日期</th>
                <td colspan="4"><p
                    class="center">{{ consignment.create_time.date() }}</p>
                </td>
              </tr>
              <tr>
                <th>产品名称</th>
                {% if consignment.measured_by_weight %}
                  <th colspan="3">净重(公斤)</th>
                {% else %}
                  <th>规格 - 型号</th>
                  <th>数量</th>
                  <th>净重(公斤)</th>
                {% endif %}
                <th>生产班组</th>
              </tr>
              {% for product in consignment.product_list %}
                {% if loop.index > (i * per_page) and loop.index <= ((i + 1) * per_page) %}
                  <tr>
                    <td>{{ product.product.name }}</td>
                    {% if  consignment.measured_by_weight %}
                      <td colspan="3">
                        {{ product.weight }}
                        {% if product.returned_weight %}
                          (退镀{{ product.returned_weight }}KG)
                        {% endif %}
                      </td>
                    {% else %}
                      <td>{{ product.spec + " - " + product.type }}</td>
                      <td>{{ product.quantity }}({{ product.unit }})</td>
                      <td>
                        {{ product.weight }}
                        {% if product.returned_weight %}
                          (退镀{{ product.returned_weight }}KG)
                        {% endif %}
                      </td>
                    {% endif %}
                    <td>
                      {{ product.team.name }}
                    </td>
                  </tr>{% endif %}
              {% endfor %}
              <tr>
                <th>备注：</th>
                <td colspan="4">{{ consignment.notes or "" }}</td>
              </tr>
              <tr>
                <td colspan="3">客户签名：</td>
                <td colspan="2">
                  总重量(公斤):{{ consignment.product_list|sum(attribute='weight') }}</td>
              </tr>
            </table>
            <p class="text-right">注:若有质量疑义，请在收货之日起三日内以书面形式告知</p>
          </div>
        {% endfor %}
      </div>
      <div class="text-center">
        <p>支付类型：{% if consignment.pay_in_cash %}现金支付&nbsp;
          {% if consignment.is_paid %}已支付{% else %}未支付{% endif %}{% else %}
          月结{% endif %}
        </p>
        <button class="btn btn-primary btn-lg" id="print">
          <i class="fa fa-print fa-fw"></i>{{ _("打印") }}
        </button>
        <a href="{{ request.args.get("url") or url_for("delivery.session_list") }}" class="btn btn-lg btn-default">
          <i class="fa fa-step-backward fa-fw"></i>{{ _("返回") }}
        </a>
      </div>
    </div>
  </div>
{% endblock %}

